package com.woniu.sharepark.config;


import com.woniu.sharepark.intercepter.AuthInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置类：视图配置
 * @author xin
 * @date 2019/6/3 11:49
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Value("${file.path}")
String path;
@Value("${file.address}")
String address;


    /**
    * 自定义异常界面配置
    * @title webServerFactoryCustomizer
    * @return: org.springframework.boot.web.server.WebServerFactoryCustomizer<org.springframework.boot.web.server.ConfigurableWebServerFactory>
    * @author xin
    * @date 2019/6/4 15:41
    */

    @Bean
    public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer(){

        return (factory -> {
            ErrorPage errorPage404 = new ErrorPage(HttpStatus.NOT_FOUND, "/404.html");
            factory.addErrorPages(errorPage404);
        });


    }


    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("operation/addComInfo.html").setViewName("pc/operation/addComInfo");
        registry.addViewController("/").setViewName("index");
        registry.addViewController("idcardtest").setViewName("idcardtesthtml");
        registry.addViewController("test").setViewName("addcommenttest");
        registry.addViewController("index").setViewName("mobile/index");
        registry.addViewController("mlogin.html").setViewName("mobile/login");
        registry.addViewController("mregister.html").setViewName("mobile/register");
        registry.addViewController("webSocket").setViewName("/lzjtesthtml/webSocket");
        registry.addViewController("carIndex").setViewName("mobile/map");
        registry.addViewController("carList").setViewName("mobile/CarIndex");
        registry.addViewController("user.html").setViewName("mobile/user");
        registry.addViewController("equipment.html").setViewName("mobile/equipment");
        registry.addViewController("goods_detail.html").setViewName("mobile/goods_detail");
        registry.addViewController("opinion.html").setViewName("mobile/opinion");
        registry.addViewController("opiniontotenant.html").setViewName("mobile/opiniontotenant");
        registry.addViewController("tenantcomment.html").setViewName("mobile/tenantcomment.html");
        registry.addViewController("npwd.html").setViewName("mobile/newPassword");
        registry.addViewController("recharge.html").setViewName("mobile/recharge");
        registry.addViewController("order_confirm.html").setViewName("mobile/order_confirm");
        registry.addViewController("shares.html").setViewName("mobile/shares");
        registry.addViewController("goods_detail1.html").setViewName("mobile/goods_detail1");
        registry.addViewController("testNull.html").setViewName("lzjtesthtml/testNull");
        registry.addViewController("order.html").setViewName("mobile/order");
        registry.addViewController("order_detail.html").setViewName("mobile/order_detail");
        registry.addViewController("order33.html").setViewName("mobile/order33");
        registry.addViewController("set.html").setViewName("mobile/set");
        registry.addViewController("idcard_add.html").setViewName("mobile/idcard_add");
        registry.addViewController("drivercard_add.html").setViewName("mobile/drivercard_add");
        registry.addViewController("password_change.html").setViewName("mobile/password_change");
        registry.addViewController("message_add.html").setViewName("mobile/message_add");
        registry.addViewController("resetPassword.html").setViewName("mobile/resetPassword");
        registry.addViewController("address.html").setViewName("mobile/address");
        registry.addViewController("testqrcode").setViewName("/lzjtesthtml/testqrcode");
        registry.addViewController("idcardtest").setViewName("/lzjtesthtml/idcardtesthtml");
        registry.addViewController("driverCardAndidCardTest").setViewName("/lzjtesthtml/driverCardAndidCardTest");
//        registry.addViewController("index.html").setViewName("pc/index");
        registry.addViewController("admin").setViewName("pc/index");
        registry.addViewController("img").setViewName("file:"+address);
        registry.addViewController("main.html").setViewName("pc/main");
        registry.addViewController("main1.html").setViewName("pc/main1");
        registry.addViewController("login.html").setViewName("pc/login");
        registry.addViewController("log.html").setViewName("pc/log");
        registry.addViewController("404.html").setViewName("pc/404");
        registry.addViewController("operation/resetPwd.html").setViewName("pc/operation/resetPwd");
        registry.addViewController("operation/carInfo.html").setViewName("pc/operation/carInfo");
        registry.addViewController("operation/carInfoCom.html").setViewName("pc/operation/carInfoCom");
        registry.addViewController("operation/carParkInfo.html").setViewName("pc/operation/carParkInfo");
        registry.addViewController("operation/complaint.html").setViewName("pc/operation/complaint");
        registry.addViewController("operation/carParkInfoCom.html").setViewName("pc/operation/carParkInfoCom");
        registry.addViewController("operation/communityInfo.html").setViewName("pc/operation/communityInfo");
        registry.addViewController("operation/addCommunity.html").setViewName("pc/operation/addCommunity");
        registry.addViewController("operation/scale.html").setViewName("pc/operation/scale");
        registry.addViewController("operation/orderDTO.html").setViewName("pc/operation/orderDTO");
        registry.addViewController("operation/allOrder.html").setViewName("pc/operation/allOrder");

        //车位相关页面
        registry.addViewController("lessorindex").setViewName("mobile/lessorindex");
        registry.addViewController("lessorinfo").setViewName("mobile/lessorinfo");
        registry.addViewController("lessororder").setViewName("mobile/lessororder");
        registry.addViewController("addcarpark").setViewName("mobile/addcarpark");


    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new AuthInterceptor());
    }



















}
